package com.ljm.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderNacosController {

    @Resource
    private RestTemplate restTemplate;

    @Value("${server-url.nacos-user-service}")
    private String serverURL;

    @GetMapping("/consumer/payment/nacos/{id}")
    public String paymentInfo(@PathVariable("id")Long id){
        return restTemplate.getForObject(serverURL+"/payment/nacos/"+id,String.class);
    }
    /// http://localhost:83/consumer/payment/nacosString/%E5%88%98%E4%BD%B3%E6%98%8E
    /*   调用链接  第一次报错，第二次运行成功  原因是在nacos 中 注册了两个 服务提供者  ，   消费者 排队调用其中一个   可以设置随机调用，但是我忘记在哪里设置了  */
    @GetMapping("/consumer/payment/nacosString/{Str}")
    public String paymentInfoString(@PathVariable("Str")String Str){
        return restTemplate.getForObject(serverURL+"/payment/nacosString/"+Str,String.class);
    }

//    @GetMapping("/consumer/payment/{id}")
//    public String paymentid(@PathVariable("id")Long id){
//        return restTemplate.getForObject(serverURL+"/payment/"+id,String.class);
//    }


}
